#include<cstdio>
#include<cstring>
using namespace std;
 
struct Moban {
    int arr[2][4], step, path[60];
 
    Moban() {
        memset(arr, 0, sizeof(arr));
        memset(path, 0, sizeof(path));
        step = 0;
    }
 
    void A() {
        for(int i=0; i<4; i++) {
            int temp = arr[0][i];
            arr[0][i] = arr[1][i];
            arr[1][i] = temp;
        }
    }
 
    void B() {
        for(int i=0; i<2; i++) {
            int temp = arr[i][3];
            arr[i][3] = arr[i][2];
            arr[i][2] = arr[i][1];
            arr[i][1] = arr[i][0];
            arr[i][0] = temp;
        }
    }
 
    void C() {
        int temp = arr[0][1];
        arr[0][1] = arr[1][1];
        arr[1][1] = arr[1][2];
        arr[1][2] = arr[0][2];
        arr[0][2] = temp;
    }
 
    void move(int i) {
        switch (i) {
        case 0:
            A();
            break;
        case 1:
            B();
            break;
        case 2:
            C();
            break;
        }
        path[step++] = i;
    }
}start, target, l[40320];
 
bool v[40320] = {false};
int front = 0, rear = -1;
 
int cantor(int a[], int len) {
    int ans = 0;
    for(int i=0; i<len; i++) {
        int count=0, index=1, f=1;
        for(int j=i+1; j<len; j++) {
            if(a[i]>a[j])
                count++;
            f *= index++;
        }
        ans += count * f;
    }
    return ans;
}
 
int cantorMoban(Moban mo) {
    int a[8] = {0};
    for(int i=0; i<2; i++)
        for(int j=0; j<4; j++)
            a[i*4 + j] = mo.arr[i][j];
    // for (int i=0; i<8; i++) cout << a[i];
    return cantor(a, 8);
}
 
void printPath(int i) {
    switch (i) {
    case 0:
        printf("A");
        break;
    case 1:
        printf("B");
        break;
    case 2:
        printf("C");
        break;
    }
}
 
int main () {
    // 初始状态赋值
    for(int i=0; i<4; i++)
        start.arr[0][i] = i + 1;
    for(int i=0; i<4; i++)
        start.arr[1][i] = 8 - i;
    l[++rear] = start;
    int st = cantorMoban(start);
    v[cantorMoban(start)] = true;
 
    // 输入目标状态
    for(int i=0; i<4; i++)
        scanf("%d", &target.arr[0][i]);
    for(int i=0; i<4; i++)
        scanf("%d", &target.arr[1][3-i]);
    int tg = cantorMoban(target);
 
    if(st == tg) {
        printf("0\n");
        return 0;
    }
             
    // 进行运算
    while (front <= rear) {
        for(int i=0; i<3; i++) {
            Moban mo = l[front];
            mo.move(i);
            if(v[cantorMoban(mo)]) continue;
            if(tg == cantorMoban(mo)) {
                printf("%d\n", mo.step);
                for(int j=0; j<mo.step; j++) {
                    printPath(mo.path[j]);
                    if (j > 59)
                        printf("\n");
                }
                return 0;
            }
            v[cantorMoban(mo)] = true;
            l[++rear] = mo;
        }
        front++;
    }
    return 0;
}